<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\Goods as GoodsModel;

/**
 * 商品
 */
class Goods extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['list'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 列表
     *
     * @ApiMethod (GET)
     */
    public function list()
    {
        if(!input('num'))
        {
            $num = 6;
        }else{
            $num = input('num');
        }
        //商品
        $data = GoodsModel::where('status', 1)->paginate($num);

        $this->success('OK',$data);
    }

    /**
     * 详情
     *
     * @ApiMethod (GET)
     */
    public function detail()
    {
        $id = input('id');
        if(!$id)
        {
            $this->error('参数错误');
        }
        //商品
        $data = GoodsModel::where('id', $id)->find();

        $this->success('OK',$data);
    }
}
